<?php

namespace App\Master\PUT;

class User extends \App\Master\CheckUser {

    /**
     * 更新个人设置
     */
    public function action() {
        $data['noset']['user_id'] = $_SESSION['user']['user_id'];
        $data['user_head'] = $this->p('head');
        
        $msg = '更新设置成功';

        if(!empty($_POST['passwd']) && !empty($_POST['repasswd'])){
            $password = $this->p('passwd');
            $repasswd = $this->p('repasswd');
            if($password !== $repasswd){
                $this->error('两次密码不正确');
            }
            $data['user_passwd'] = \Core\Func\CoreFunc::generatePwd($_SESSION['user']['user_mail'] . $password, 'PRIVATE_KEY');
            
            setcookie('tm', NULL, time() - 10, '/');
            session_destroy();
            $msg .= '请重新登录';
        }

        $this->db('user')->where('user_id = :user_id')->update($data);


        $this->success($msg, $this->url('Master-User-action'));
    }

}
